package com.hentie.mathlib;

public class Vector3 {
	
	//The x,y,z representation
	float[] xyz = new float[3];
	
	public Vector3(float x,float y,float z)
	{
		xyz[0]=x;
		xyz[1]=y;
		xyz[2]=z;
	}
	
	public void Set(float x,float y,float z)
	{
		xyz[0]=x;
		xyz[1]=y;
		xyz[2]=z;
	}
	
	public Vector3(Vector2 copy,float z)
	{
		xyz[0] = copy.xy[0];
		xyz[1]= copy.xy [1];
		xyz[2] = z;
	}
	
	public float length()
	{
		return (float)Math.sqrt(lengthSquared());
		
	}
	
	public float lengthSquared()
	{
		return xyz[0]*xyz[0] + xyz[1]*xyz[1] + xyz[2]*xyz[2];
	}
	
	public float X(){ return xyz[0];}
	public float Y(){return xyz[1];}
	public float Z(){return xyz[2];}
	
	public void normalize()
	{
		float length = length();
		
		xyz[0]/=length;
		xyz[1]/=length;
		xyz[2]/=length;
	}
	
	public void Subtract(Vector3 vector)
	{
		this.xyz[0] -= vector.xyz[0];
		this.xyz[1] -= vector.xyz[1];
		this.xyz[2] -= vector.xyz[2];
	}
	
	public static Vector3 One()
	{
		return new Vector3(1,1,1);
	}
	public static Vector3 Zero()
	{
		return new Vector3(0,0,0);
	}
	
	public static float dot(Vector3 first,Vector3 second)
	{
		return first.xyz[0]*second.xyz[0]+first.xyz[1]*second.xyz[1] + first.xyz[2]*second.xyz[2];
	}
	public static Vector3 cross(Vector3 first,Vector3 second)
	{
		return new Vector3( (first.xyz[1]*second.xyz[2]) - (second.xyz[1]*first.xyz[2]),
				-(first.xyz[0]*second.xyz[2]) + (second.xyz[0]*first.xyz[2]),
				(first.xyz[0]*second.xyz[1]) - (first.xyz[1]*second.xyz[0]));
	}
	

}